package chpt04;

import java.util.Arrays;
import java.util.Scanner;

interface IntegerStack {
	public Integer push(Integer item);
	public Integer pop(); 
	public Integer peek(); 
	public boolean empty(); 
	public int size(); 
}

class ArrayIntegerStack implements IntegerStack {
	private Integer[] arr;
	private int top=0;

	public ArrayIntegerStack(int capacity) {
		arr=new Integer[capacity];
	}

	@Override
	public Integer push(Integer item) {
		if(item==null||top==arr.length)
			return null;
		arr[top++]=item;
		return item;
	}

	@Override
	public Integer pop() {
		if(top==0)
			return null;
		return arr[--top];
	}

	@Override
	public Integer peek() {
		if(top==0)
			return null;
		return arr[top-1];
	}

	@Override
	public boolean empty() {
		if(top==0)
			return true;
		return false;
	}

	@Override
	public int size() {
		return top;
	}

	@Override 
	public String toString() {
		return Arrays.toString(arr);
	}

}

public class ArrayStack {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		IntegerStack stack=new ArrayIntegerStack(n);
		int m=in.nextInt();
		for (int i = 0; i < m; i++) {
			System.out.println(stack.push(in.nextInt()));
		}
		System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
		System.out.println(stack.toString());
		int x=in.nextInt();
		for (int i = 0; i < x; i++) {
			System.out.println(stack.pop());
		}
		System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
		System.out.println(stack.toString());
		in.close();
	}
}
